如下图,SpringBoot默认使用Tomcat作为嵌入式的Servlet容器。 我们也可以在配置文件中进行一些配置。

在配置文件中进行简单的配置:

SpringBoot默认使用的是Tomcat,如果要切换其他容器,则只需要在pom文件中去掉Tomcat依赖,添加其他依赖即可。
如将Tomcat换成Jetty,如下图,添加修改依赖即可:
<!-- 引入web模块 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <!-- 去掉tomcat --> <exclusion> <artifactId>spring-boot-starter-tomcat</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> </exclusions> </dependency> <!--引入其它的jetty容器--> <dependency> <artifactId>spring-boot-starter-jetty</artifactId> <groupId>org.springframework.boot</groupId> </dependency>
|
SpringBoot默认还支持Jetty和Undertow容器,Undertow是一个高性能非阻塞的Servlet容器,并发性能很好,但是不支持JSP。Jetty更适合开发一些长连接Web应用,如Web聊天。